package com.example.friend.controller.exam;

import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.Result;
import com.example.common.core.domain.TableDataInfo;
import com.example.common.core.enums.ResultCode;
import com.example.friend.domain.exam.dto.ExamQueryDTO;
import com.example.friend.service.exam.ExamService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 23050
 * @version 1.0
 * @description: TODO
 * @date 2025/3/8 20:00
 */
@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {


    @Resource
    private ExamService examService;



    /**
     * @author 23050
     * @description:  C端用户类
     * @date: 2025/3/8 20:19
     * @param examQueryDTO
     * @return com.example.common.core.domain.TableDataInfo
     * /semiLogin 表示版登录状态，可以不需要登录访问
     */
    @GetMapping("/semiLogin/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO){
        return getTableDataInfo(examService.list(examQueryDTO));
    }


    /**
     * @author 23050
     * @description:  未完赛竞赛列表  历史竞赛列表
     * @date: 2025/3/10 21:59
     * @param examQueryDTO
     * @return com.example.common.core.domain.TableDataInfo
     */
    @GetMapping("/semiLogin/redis/list")
    public TableDataInfo redisList(ExamQueryDTO examQueryDTO){
        return examService.redisList(examQueryDTO);
    }


    /**
     * @author 23050
     * @description:  刷新缓存
     * @date: 2025/3/11 21:37
     * @return com.example.common.core.domain.Result
     */
    @GetMapping("/semiLogin/redis/refreshCache")
    public Result refreshCache(){
        examService.refreshCache();
        return new Result(1,"刷新成功","");
    }



    /**
     * @author 23050
     * @description:  获取竞赛中的第一题
     * @date: 2025/5/1 17:37
     * @param examId
     * @return com.example.common.core.domain.Result
     */
    @GetMapping("/getFirstQuestion")
    public Result getFirstQuestion(Long examId){
        //获取当前竞赛中题目的顺序 返回第一个题目id
        //从redis中获取  exam:question:list:examId - questionId的list
        return new Result(ResultCode.SUCCESS.getCode(),"获取竞赛的第一个题目成功",examService.getFirstQuestion(examId));
    }


    /**
     * @author 23050
     * @description:  上一题
     * @date: 2025/3/27 19:41
     * @return com.example.common.core.domain.Result
     * 在Redis中找    exam:question:list:examId - [questionId]
     *
     */
    @GetMapping("/preQuestion")
    public Result preQuestion(Long examId, Long questionId){
        return new Result(ResultCode.SUCCESS.getCode(),
                "success",
                examService.preQuestion(examId,questionId));
    }


    /**
     * @author 23050
     * @description:  下一题
     * @date: 2025/3/27 19:41
     * @return com.example.common.core.domain.Result
     * 在Redis中找    exam:question:list:examId - [questionId]
     */
    @GetMapping("/nextQuestion")
    public Result nextQuestion(Long examId, Long questionId){
        return new Result(ResultCode.SUCCESS.getCode(),
                "success",
                examService.nextQuestion(examId,questionId));
    }









}
